package com.wz.project.system.help.service.impl;

import com.wz.common.utils.security.ShiroUtils;
import com.wz.project.system.dept.mapper.DeptMapper;
import com.wz.project.system.help.domain.SysUserHelp;
import com.wz.project.system.help.mapper.SysUserHelpMapper;
import com.wz.project.system.help.service.SysUserHelpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author zn kai
 * @create 2021-08-21 17:58
 */
@Service
public class SysUserHelpServiceImpl implements SysUserHelpService {

    @Autowired
    private SysUserHelpMapper sysUserHelpMapper;

    @Autowired
    private DeptMapper deptMapper;
    @Override
    public int insetUserHelp(SysUserHelp userHelp) {
        String loginName = ShiroUtils.getLoginName();
        String ancestors = deptMapper.selectUserByDeptFiledAncestors(loginName).split(",")[0];
        userHelp.setUserType(Integer.parseInt(ancestors.equals("0")?"1":"2"));

        userHelp.setCreateBy(loginName);
        userHelp.setCreateTime(new Date());
        userHelp.setStatus(0);
        return sysUserHelpMapper.insertSelective(userHelp);
    }

    @Override
    public List<SysUserHelp> selectHelpList(SysUserHelp userHelp) {
        return sysUserHelpMapper.selectHelpList(userHelp);
    }

    @Override
    public SysUserHelp selectHelpById(Long helpId) {
        return sysUserHelpMapper.selectByPrimaryKey(helpId);
    }
}
